package com.nd.android.u.ui.beanStarApp;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.SpannableString;
import android.widget.ImageView;

import com.common.android.utils.smiley.Smiley;
import com.nd.android.u.allCommonUtils.ToastUtils;
import com.nd.android.u.controller.ChatConst.KEY;
import com.nd.android.u.controller.ChatConst.LocalMessageType;
import com.nd.android.u.controller.ChatConst.MessageContentType;
import com.nd.android.u.controller.bean.contact.BaseGroupContactItem;
import com.nd.android.u.controller.bean.contact.ForwardingParam;
import com.nd.android.u.ui.ChatEntry;
import com.nd.android.u.ui.R;
import com.nd.android.u.ui.chatUiUtils.ChatCommonUtils;
import com.nd.android.u.ui.chatUiUtils.ChatViewUtil;
import com.product.android.commonInterface.chat.ChatGroup;

/**
 * 群消息联系人
 * <br>Created 2014-10-30 下午2:36:27
 * @version  
 * @author   cb		
 * @see 	 
 */
public class GroupContactItem extends BaseGroupContactItem{
	@Override
	public SpannableString getContentText() {
		if (spannableText==null){
			spannableText=ChatCommonUtils.getSmileySpannableString(mLastMsgContent,Smiley.TYPE_CHAT, mLastMsgId);	
		}
	    return spannableText;
	}
	
	@Override
	public void onClickHeadPortrait(Context ctx) {
		long id = convertId();
		if (id < 0) {
			return;
		}
		Bundle bundle=new Bundle();
		if (subType==ChatGroup.getDiscussionGroupType()){
			bundle.putLong(KEY.GID, id);
			ChatEntry.INSTANCE.chatCallOtherModel_UI.gotoDiscussionManagerActivity(ctx, bundle);
		}else if (subType==ChatGroup.getNormalGroupType()){
			bundle.putLong(KEY.GID, id);
			ChatEntry.INSTANCE.chatCallOtherModel_UI.gotoGroupManagerActivity(ctx, bundle);
		}else if (subType==ChatGroup.getDepartGroupType()){
			bundle.putLong(KEY.DEPTID, id);
			ChatEntry.INSTANCE.chatCallOtherModel_UI.gotoGroupManagerActivity(ctx, bundle);
		}else if (subType== ChatGroup.getUntidGroupType()){
			Class<?> target=getDisplayClass();
			if (target!=null){
				return;
			}
			Intent intent = new Intent(ctx, target);
			ctx.startActivity(intent);
		}else{
			return;
		}
	}
	
	@Override
	public void onForwarding(Activity activity, ForwardingParam forwardingParam) {
		if (forwardingParam.mMsgType == MessageContentType.FILE || 
			forwardingParam.mMsgType == MessageContentType.OLD_FILE) {
			ToastUtils.display(activity, R.string.chat_transmit_group);
			return;
		}
		long id = convertId();
		if (id < 0) {
			return;
		}
		Bundle bundle = new Bundle();
		bundle.putString(KEY.REPOST_DATA, forwardingParam.mGenerateId);
		bundle.putLong(KEY.GID, id);
		bundle.putString(KEY.NAME, name);
		bundle.putInt(KEY.MESSAGE_TYPE, LocalMessageType.GROUP);
		bundle.putInt(KEY.GROUPTYPE, subType);
		Intent intent = new Intent(activity, getDisplayClass());
		intent.putExtras(bundle);
		ChatViewUtil.showDlg(activity, intent,getMsgTitle(activity));
	}
	
	@Override
	public void displayHeadPortrait(ImageView iv) {
		iv.setTag(convertId());
		iv.setPadding(6, 6, 6, 6);
		ChatEntry.INSTANCE.chatCallOtherModel_UI.setGroupAvator(
				iv.getContext(), iv, convertId());
	}
}
